
#include <iostream>
#include <string>

using namespace std;

int lengthLongestPath(const string& input) {
    int ret = 0;
    int depthSize[100]; /**max depth is 100 */
    int tCount = 0;
    int charCnt = 0;
    bool findFile = false;

    for (int i = 0; i < input.size(); i++)
    {
        char cur = input.at(i);
        if (cur == '\n')
        {
            int fileSize = 0;
            if (tCount > 0)
            {
                fileSize = depthSize[tCount - 1] + charCnt + tCount;
            }
            else
            {
                fileSize = charCnt;
            }

            if (findFile)
            {
                findFile = false;
                if (fileSize > ret)
                {
                    ret = fileSize;
                }
            }
            else
            {
                depthSize[tCount] = fileSize;
            }

            tCount = 0; /** reset '\t' countor */
            charCnt = 0; /** reset 'char' counter */
        }
        else if (cur == '\t')
        {
            tCount++;
        }
        else
        {
            if (cur == '.')
            {
                findFile = true;
            }
            charCnt++;
        }
    }

    if (findFile)
    {
        int fileSize = 0;
        if (tCount > 0)
        {
            fileSize = depthSize[tCount - 1] + charCnt + tCount;
        }
        else
        {
            fileSize = charCnt;
        }

        if (fileSize > ret)
        {
            ret = fileSize;
        }
    }

    return ret;
}







int main(int argc, char* argv[])
{
    cout << "max size: " << lengthLongestPath("dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext")<<endl;
    getchar();
    return 0;
}